package com.sali.rule;

import org.apache.commons.lang3.StringUtils;


public class DomainRule implements Rule {
    private static Rule rule;

    static {
        rule = new DomainRule();
    }

    public static Rule getInstance() {
        return rule;
    }


    @Override
    public Object invoke(Object value) {
        String host = (String) value;
        if (StringUtils.isEmpty(host)) {
            return "";
        }
        if (!host.contains("BODY")) {
            return host;
        }

        int index = host.indexOf("> BODY");
        if (index == -1) {
            index = host.indexOf(" BODY");
        }

        if (index != -1) {
            return host.substring(0, index);
        }

        return host;
    }


    public static void main(String[] args) {
        Rule instance = DomainRule.getInstance();
        Object invoke = instance.invoke("heathcarerate.org> BODY=8BITMIME");
        System.out.println(invoke);
    }


}
